<template>
  <el-dialog
    :title="'导入数据'"
    v-model="visible"
    :width="400"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <sk-tabs type="border-card">
      <el-form ref="dialogForm" label-width="100px" label-position="right">
        <el-row>
          <el-col :span="22">
            <el-form-item label="模版" prop="url">
              <el-link :href="url" target="_blank">点击下载模版</el-link>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="文件" prop="file">
              <el-upload
                class="upload-demo"
                ref="upfile"
                :action="this.action"
                :limit="1"
                :headers="headers"
                :on-success="success"
                :on-error="success"
              >
                <el-button type="primary">点击上传</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </sk-tabs>
  </el-dialog>
</template>

<script>
import sysConfig from "@/config";
export default {
  emits: ["success", "closed", "update:modeValue"],
  data() {
    return {
      visible: false,
      isSaveing: false,
      url: null,
      action: null,
      headers: {},
    };
  },
  mounted() {
    let token = this.$TOOL.data.get("TOKEN");
    if (token) {
      this.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token;
    }
  },
  methods: {
    //显示
    close() {
      this.visible = false;
      this.$emit("update:modeValue", false);
      this.$emit("closed");
    },
    open() {
      this.visible = true;
      return this;
    },
    success(data) {
      if ((data.success ?? false) == false) {
        this.$message.error("上传失败。" + data.message);
        this.$refs.upfile.clearFiles();
      } else {
        this.$emit("success");
        this.close();
      }
    },
    uploadfile() {},
    //表单注入数据
    setData(url, action) {
      this.url = url;
      this.action = action;
    },
  },
};
</script>
<style></style>
